package doan.chuyennganh.model;

import java.util.ArrayList;

public class ListClass {
	private static ListClass instance = null;
	private ArrayList<ClassStudent> list = null;
	
	public void setList( ArrayList<ClassStudent> list) {
		this.list = list;
	}
	public  ArrayList<ClassStudent>  getAllClass() {
		return list;
	}
	public ClassStudent getClass(String id){
		for (ClassStudent st : list) {
			if(st.getMalop().equals(id)){
				return st;
			}
		}
		return null;
	}
	public boolean isContains(ClassStudent cls){
		if(list.contains(cls)){
			return true;
		}
		return false;
	}
	public int addClass(ClassStudent cls) {
		if(list.contains(cls)){
			return 0;
		}
		list.add(cls);
		return 1;
	}
	public int removeClass(String classID) {
		ClassStudent st = getClass(classID); 
		if( st == null){
			return 0;
		}
		list.remove(st);
		return 1;
	}
	public int updateClass(ClassStudent cls) {
		ClassStudent st = getClass(cls.getMalop()); 
		if( st == null){
			return 0;
		}
		list.add(list.indexOf(st), cls);
		list.remove(st);
		return 1;
	}
	private ListClass(){
		list = new ArrayList<ClassStudent>();
	}
	public static synchronized ListClass getInstance() {
		if(instance == null){
			instance = new ListClass();
		}
		return instance;
	}
	
}
